package com.liu.repository;

import com.liu.domain.VoteCount;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Created by liu on 17-10-31.
 */
public interface VotecountRepository extends JpaRepository<VoteCount,Integer> {

    @Transactional
    @Modifying
    @Query("update VoteCount v set v.count = v.count+1 where v.id = ?1")
    int updateCount(int id);                                                    //投票加一

    @Query("select s from VoteCount s order by s.count desc")
    public List<VoteCount> findShunxun();                   //按大小顺序


    @Query("select count(s) from VoteCount s where s.roomId = ?1")
    public int findbyroom(int roomId);                //

    //清空表内数据
    @Transactional
    @Modifying
    @Query("delete from VoteCount ")
    int del();


    //查询有几条数据
    @Query("select count(s) from VoteCount s")
    public int findCount();


}
